#include <iostream>
#include <vector>
using namespace std;
#include "check.h"


int min_flips=INT_MAX;
int flips = 0;

void traceback(vector<bool> vec,int a,int b)
{
    short result = check(vec,a,b);
    if(result != 0)
    {
        if(result == 2)
        {
            min_flips = flips<min_flips?flips:min_flips;
        }
        return ;
    }
    for(int i=a;i<b;i++)
    {
        vec = overturn(vec,i,a,b);
        flips++;
        traceback(vec,a,b);
        flips--;
    }
}

int calculate_a_line(vector<bool> differed_line,int a,int b)
{
    min_flips = INT_MAX;
    flips = 0;
    traceback(differed_line,a,b);
    if(min_flips == INT_MAX)
    {
        return -1;
    }
    return min_flips;
}